package alarm.ruiqi.com.alarm_pro.options.base;

import android.content.Intent;
import android.os.Bundle;

import com.ab.activity.AbActivity;

import alarm.ruiqi.com.alarm_pro.service.MobileApplication;

/**
 * Created by 徐宇健 on 2015/6/30 0030.
 */
public class BaseActivity extends AbActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        MobileApplication.getInstance().putCtx(this);
        super.onCreate(savedInstanceState);
    }

    //region 跳转相关
    /**
     * 通过Class跳转界面
     */
    public void startActivity(Class<?> cls) {
        startActivity(cls, null);
    }

    /**
     * 含有Bundle通过Class跳转界面
     */
    public void startActivity(Class<?> cls, Bundle bundle) {
        Intent intent = new Intent();
        intent.setClass(this, cls);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        startActivity(intent);
    }

    /**
     * 通过Action跳转界面
     */
    public void startActivity(String action) {
        startActivity(action, null);
    }

    /**
     * 含有Bundle通过Action跳转界面
     */
    public void startActivity(String action, Bundle bundle) {
        Intent intent = new Intent();
        intent.setAction(action);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        startActivity(intent);
    }

    /**
     * 含有Bundle通过Class打开编辑界面
     */
    public void startActivityForResult(Class<?> cls, Bundle bundle,
                                       int requestCode) {
        Intent intent = new Intent();
        intent.setClass(this, cls);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        startActivityForResult(intent, requestCode);
    }

    /**
     * 带有右进右出动画的退出
     */
    @Override
    public void finish() {
        super.finish();
        MobileApplication.getInstance().removeCtx(this);//移除
    }

    /**
     * 默认退出
     */
    public void defaultFinish() {
        super.finish();
        MobileApplication.getInstance().removeCtx(this);//移除
    }
    //endregion
}
